package com.sntk.organauthomanager.application.dispatch;

import com.sntk.organauthomanager.application.dto.AuthoInfo;
import com.sntk.organauthomanager.application.dto.HisOperatorInfo;
import com.sntk.organauthomanager.application.dto.ResponseData;
import com.sntk.organauthomanager.application.dto.ServiceInfo;
import com.sntk.organauthomanager.application.service.InteriorRegistrationService;
import com.sntk.organauthomanager.infrastructure.autho.PassToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: LoginDispatch
 * @author: wgchao
 * @createTime: 2020/9/7 4:13 PM
 * @Description: 内部授权
 */
@RestController
@RequestMapping("/sinohis/osm/interior/login")
@Api(value="LoginDispatch",tags={"内部授权"})
public class LoginDispatch {
    @Autowired
    private InteriorRegistrationService interiorRegistrationService;

    /**
     * 服务注册
     * @return
     */
    @PostMapping("/registration")
    @PassToken
    @ApiOperation(value="服务注册")
    public ResponseData<String> serviceRegistration(@RequestBody ServiceInfo serviceInfo, HttpServletRequest request){
        String serviceCode = interiorRegistrationService.serviceRegistration(serviceInfo, request);
        return ResponseData.success().setData(serviceCode);
    }

    /**
     * 用户认证
     * @return
     */
    @PostMapping("/autho/passtoken")
    @ApiOperation(value="用户认证")
    public ResponseData<HisOperatorInfo> autho(@RequestBody AuthoInfo authoInfo){
        HisOperatorInfo operatorInfo = interiorRegistrationService.autho(authoInfo.getAccessToken());
        return ResponseData.success().setData(operatorInfo);
    }


}
